package org.hrqing.authorization.security;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @auther Hrqing
 */
@Component
public class JpaAuditor implements AuditorAware<Auditor> {

    @Override
    public Optional<Auditor> getCurrentAuditor() {
        SecurityUser securityUser = SecurityUtils.getSecurityUser();
        if (securityUser == null) {
            return Optional.empty();
        }
        return Optional.of(new Auditor(securityUser.getId(), securityUser.getName(), securityUser.getCertNumber(), securityUser.getMobile()));
    }
}
